import java.util.*;
import java.lang.*;
import java.io.*;

public class GraphTest
 {
  public static void main(String args[])
  {
	try
	 {
	 	Graph<Integer> graph1 = new Graph<Integer>();
	 
		FileInputStream fstream = new FileInputStream(args[0]);
  		BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
		boolean undirected = true;

  		String strLine, strwrite[];
		int numberOfVertices = 0;
		int numberOfEdges = 0;
		
		String strLine1 = br.readLine();
		if(strLine1.equals("D"))
		{
		    undirected = false;
		}
		HashSet<Vertex> vertex = new HashSet<Vertex>();
		HashSet<Edge> edge = new HashSet<Edge>();
		Hashtable<Integer, Vertex> vertexhash = new Hashtable<Integer, Vertex>();
					
			strLine = br.readLine();
		
			String a[] = strLine.split(" ");
			numberOfVertices = Integer.parseInt(a[0]);
			numberOfEdges =  Integer.parseInt(a[1]);
			System.out.println("NO OF VERTECES AND EDGES ARE:"); 
			System.out.println(numberOfVertices+"\t"+numberOfEdges);
					
			for(int k=1;k<=numberOfVertices;k++)
			{
				Vertex<Integer,Integer> vertex1 = new Vertex<Integer,Integer>(k,0);
				System.out.println("Inserted Vertex:" +k);
				graph1.addVertex(vertex1);
				
			}
			while((strLine = br.readLine()) != null)
			{
				String a1[] = strLine.split(" ");
				Integer leftV = Integer.parseInt(a1[0]);
				Integer rightV =  Integer.parseInt(a1[1]);
				//Double w = Double.parseDouble(a1[2]);
				
				Vertex<Integer,Integer> vertex1 = graph1.getVertexNode(leftV);
				Vertex<Integer,Integer> vertex2 = graph1.getVertexNode(rightV);
											
				Edge<Integer> edge1 = new Edge<Integer>(vertex1, vertex2);
				System.out.println("Inserted edge: (" +leftV+", "+ rightV+")");
				graph1.addEdge(edge1);
							
				if(undirected == true)
				{
						
					Edge<Integer> edge2 = new Edge<Integer>(vertex2, vertex1);
					System.out.println("Inserted edge: (" +rightV+", "+ leftV+")");
					graph1.addEdge(edge2);
				}
			}
			fstream.close();	
			FileWriter fstream1 = new FileWriter("out.txt");
  			BufferedWriter out = new BufferedWriter(fstream1);
 			
			if(undirected == true)
			{
				out.write("U");
				out.write("\n");
			}
			else
			{
				out.write("D");
				out.write("\n");
			}
			numberOfVertices = graph1.getNoOfVertices();
			System.out.println(numberOfVertices);
			numberOfEdges = graph1.getNoOfEdges();
			out.write(numberOfVertices);
			out.write(numberOfEdges);
			out.write("\n");
			String ccs = graph1.toString();
			
			for(int i=0;i<graph1.getNoOfEdges();i++)
			{
				strwrite = ccs.split(", ");
				System.out.println(strwrite[i]);
				out.write(strwrite[i]);
				out.write("\n");
			}			
			System.out.println("\n Graph After removing edge (1, 2) and vertex 2");
			
			Vertex v = graph1.getVertexNode(2);
			Vertex v1 = graph1.getVertexNode(1);
			Vertex v2 = graph1.getVertexNode(2);
			Edge e1 = graph1.getEdgeNode(v1, v2);
			Edge e2 = graph1.getEdgeNode(v2, v1);
			
			graph1.removeEdge(e1);
			if(undirected == true)
			{
				graph1.removeEdge(e2);
			}
			graph1.removeVertex(v);
			System.out.printf("n = %d, m = %d\n", graph1.getNoOfVertices(), graph1.getNoOfEdges());
			
			ArrayList tcs = graph1.getEdges();
			Iterator iter1 = tcs.iterator();
			
			while(iter1.hasNext())
				{
					System.out.println(iter1.next());
				}		
			out.close();
		
	}	
	catch(Exception e)
	{
		e.printStackTrace();
	}
  }
}
			
